import request from '@/utils/request'

const act_dsn_form_defineApi = {
  list: '/act_dsn_form_define/list',
  view: '/act_dsn_form_define/view',
  save: '/act_dsn_form_define/save',
  findOptionalProcessList: '/act_dsn_form_define/findOptionalProcessList',
  flowImage: '/flow/viewCharUnpublishedDiagram',
  queryCategory: '/act_dsn_form_define/queryCategory',
  editCheck: '/act_dsn_form_define/editCheck',
  publish: '/act_dsn_form_define/publish',
  getMaxDefineByKey: '/act_dsn_form_define/getMaxDefineByKey',
  enable: '/act_dsn_form_define/enable',
  formStatistics: '/act_dsn_form_define/formStatistics',
  useNum: '/act_dsn_form_define/useNum',
  limitSave: '/act_dsn_form_define/limitSave',
  updateMaxFormDefine: '/act_dsn_form_define/updateMaxFormDefine'
}

/**
 * 仅更新流程表单, 不发布流程
 * @param {*} formid
 */
 export function updateMaxFormDefine (formid) {
  return request({
    url: act_dsn_form_defineApi.updateMaxFormDefine,
    method: 'post',
    params: { formid }
  })
}

/**
 * 测试连接数据源,数据源被流程引用的次数
 * @param {*} parameter
 */
 export function useNum (id) {
  return request({
    url: act_dsn_form_defineApi.useNum,
    method: 'post',
    params: { id }
  })
}

/**
     * 统计表单定义当前的 1. 最高版本, 2. 正在运行的流程实例数, 3. 已完成的流程实例数, 
     * @param modelKey
     * @return Map<maxVersion: 最高版本, currently: 正在运行的流程实例数,  complete:  已完成的流程实例数>
     */
  export function formStatistics (modelKey) {
    return request({
      url: act_dsn_form_defineApi.formStatistics,
      method: 'post',
      params: {
        modelKey
      }
    })
  }

 /**
     * 通过key查询最大版本的流程表单定义
     * @param modelKey 流程模型key
     * @return
     */
export function getMaxDefineByKey (modelKey) {
  return request({
    url: act_dsn_form_defineApi.getMaxDefineByKey,
    method: 'post',
    params: {
      modelKey
    }
  })
}
/**
 * 停用
 * @param id 表单id
 * @return
 */
export function enable (id, enable) {
  return request({
    url: act_dsn_form_defineApi.enable,
    method: 'post',
    params: { id, enable }
  })
}

/**
 * 流程表单定义发布
 * @param formid 表单id
 * @param modelKey 模型key
 * @param tenantid 租户id
 * @return
 */
export function publish (formid, modelKey, tenantid) {
  return request({
    url: act_dsn_form_defineApi.publish,
    method: 'post',
    params: {
      formid,
      modelKey,
      tenantid
    }
  })
}

/**
 * 流程表单编辑校验
 * @param {*} formid
 */
export function editCheck (formid) {
  return request({
    url: act_dsn_form_defineApi.editCheck,
    method: 'post',
    params: {
      formid
    }
  })
}

/**
 * 删除流程定义
 * @param {*} id
 */
export function delAct_dsn_form_define (id) {
  return request({
    url: act_dsn_form_defineApi.del + '/' + id,
    method: 'post'
  })
}

/**
 * 保存流程定义
 * @param {*} parameter
 */
export function saveAct_dsn_form_define (data, params) {
  return request({
    url: act_dsn_form_defineApi.save,
    method: 'post',
    data: data,
    params: params
  })
}

/**
 * 保存流程定义
 * @param {*} parameter
 */
 export function limitSave (data) {
  return request({
    url: act_dsn_form_defineApi.limitSave,
    method: 'post',
    data: data
  })
}

/**
 * 查询未配置的流程列表
 * @param {*} id
 */
export function findOptionalProcessList (parameter) {
  return request({
    url: act_dsn_form_defineApi.findOptionalProcessList,
    method: 'post',
    data: parameter
  })
}

/**
 * 查看流程表单定义
 * @param {*} id
 */
export function viewAct_dsn_form_define (param) {
  return request({
    url: act_dsn_form_defineApi.view,
    method: 'post',
    params: param
  })
}
/**
 *  流程表单定义分页列表
 * @param {*} parameter
 */
export function queryAct_dsn_form_defineList (pageinfo) {
  return request({
    url: act_dsn_form_defineApi.list,
    method: 'post',
    data: pageinfo
  })
}

/**
 * 得到流程图
 */
export function flowImage (data) {
  return request({
    url: act_dsn_form_defineApi.flowImage,
    method: 'post',
    params: data,
    responseType: 'blob'
  })
}

/**
 * 查询流程类型出现次数最多的前十个
 */
export function queryCategory () {
  return request({
    url: act_dsn_form_defineApi.queryCategory,
    method: 'post'
  })
}
